package com.example.basicdemo.controller;


import com.alibaba.fastjson.JSONObject;
import com.isyscore.os.config.client.annotation.IscValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/${api-module}/demo")
public class DemoController {


    @IscValue(value = "basic-demo-xyz123.flag")
    private Boolean flag;

    @IscValue(value = "basic-demo-xyz123.mode")
    private String mode;

    @IscValue(value = "basic-demo-xyz123.code")
    private Integer code;

    /**
     * 获取当前动态配置项
     */
    @GetMapping("getDynamicConfig")
    public DemoBaseResult getDynamicConfig() {
        JSONObject resultJson = new JSONObject();
        resultJson.put("message", "您已成功获取动态配置信息");
        JSONObject configJson = new JSONObject();
        configJson.put("flag", flag);
        configJson.put("mode", mode);
        configJson.put("code", code);
        resultJson.put("data", configJson);
        DemoBaseResult.Data data = new DemoBaseResult.Data()
                .setResult(resultJson);
        return new DemoBaseResult().setData(data);
    }


}
